<?php
/**
 * Plugin Name:       POS For Woocommerce by gzdsx
 * Plugin URI:        https://www.gzdsx.cn
 * Description:       Wordpress主题定制，插件开发，APP开发小程序开发找大师兄，微信：gzdsx1985
 * Version:           1.0.0
 * Requires at least: 6.2
 * Requires PHP:      7.0
 * Author:            贵州大师兄
 * Author URI:        https://www.gzdsx.cn
 * License:           GPL v2 or later
 * License URI:       https://www.gzdsx.cn
 * Update URI:        https://www.gzdsx.cn
 */

define('GZDSX_POS', true);
define('GZDSX_POS_VERSION', '1.0.0');
define('GZDSX_POS_URL', plugins_url('', __FILE__));
define('GZDSX_POS_PATH', dirname(__FILE__));
define('GZDSX_POS_TEMPLATE_PATH', dirname(__FILE__).'/templates/');

register_activation_hook(__FILE__, 'gzdsx_pos_activation');
register_deactivation_hook(__FILE__, 'gzdsx_pos_deactivation');
function gzdsx_pos_activation()
{
    $post = get_post(get_option('gzdsx_pos_page_id'));
    if (!$post) {
        $pos_page_id = wp_insert_post([
            'post_title' => 'GZDSX Pos Page',
            'post_type' => 'page',
            'post_name' => 'gzdsx-pos',
            'post_status' => 'publish'
        ]);
    }else{
        $pos_page_id = $post->ID;
    }

    update_post_meta($pos_page_id, '_wp_page_template', 'gzdsx-pos-page.php');
}

function gzdsx_pos_deactivation()
{

}

add_action('init', function () {
    wp_localize_script(
        'wp-api',
        'wpApiSettings',
        array(
            'root' => esc_url_raw(rest_url()),
            'nonce' => wp_create_nonce('wp_rest')
        )
    );
});

require_once 'includes/load.php';
require_once 'includes/ajax.php';